{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#51CTO课程频道：http://edu.51cto.com/lecturer/index/user_id-12330098.html\n",
    "#优酷频道：http://i.youku.com/sdxxqbf\n",
    "#微信公众号：深度学习与神经网络\n",
    "#Github：https://github.com/Qinbf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.40993477 -0.01397269  0.11863638  0.46172817  0.49044897 -0.72700986]\n"
     ]
    }
   ],
   "source": [
    "#输入数据\n",
    "X = np.array([[1,0,0,0,0,0],\n",
    "              [1,0,1,0,0,1],\n",
    "              [1,1,0,1,0,0],\n",
    "              [1,1,1,1,1,1]])\n",
    "#标签\n",
    "Y = np.array([-1,1,1,-1])\n",
    "#权值初始化，1行3列，取值范围-1到1\n",
    "W = (np.random.random(6)-0.5)*2\n",
    "print(W)\n",
    "#学习率设置\n",
    "lr = 0.11\n",
    "#计算迭代次数\n",
    "n = 0\n",
    "#神经网络输出\n",
    "O = 0\n",
    "\n",
    "def update():\n",
    "    global X,Y,W,lr,n\n",
    "    n+=1\n",
    "    O = np.dot(X,W.T)\n",
    "    W_C = lr*((Y-O.T).dot(X))/int(X.shape[0])\n",
    "    W = W + W_C"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgoAAAFdCAYAAABiokWHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3Xl4VNX9x/H3QcMixaisbhURVMQFE8FSVFywSlncqjb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dgo4WOwy7Z2AF2D/l0SeJ/9EegFHAW0w/pMi4Ezg/5d4rzfGpZ9Z7XHRqHf\nWnb/cB1rUdtnaX+sYd0NG7DLJJuHbfXDnnN/LI61RPjln8SaPCtvZ4Q9Zyfwu0qvG4RdJrkVG8XZ\nOujfJY777ADgWSxYbQAeB/ar9Jwf9xm2Rvl0rBlqO9aF8WjoBJCqW9n/FF9il87OBU6pdNzNrPT8\nM4C8sucvA34b9O+QyPsMuL1sPxUCa7ArJs6Id81Bb9jA4NIqvsMm6FiLzj7TsfbjZaRVnSt/F/ac\nmBxrruyNRERERHaRjJdHioiISJwoKIiIiEhECgoiIiISkYKCiIiIRKSgICIiIhEpKIiIiEhECgoi\nIiISkYKCiIiIRKSgICIiIhEpKIiIiEhECgoiIiIS0f8DVeM1xM99vvUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2b374a09f28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "for _ in range(100000):\n",
    "    update()#更新权值\n",
    "    #-0.1,0.1,0.2,-0.2\n",
    "    #-1,1,1,-1\n",
    "\n",
    "\n",
    "#正样本\n",
    "x1 = [0,1]\n",
    "y1 = [1,0]\n",
    "#负样本\n",
    "x2 = [0,1]\n",
    "y2 = [0,1]\n",
    "\n",
    "def calculate(x,root):\n",
    "    a = W[3]\n",
    "    b = W[2]+x*W[4]\n",
    "    c = W[0]+x*W[1]+x*x*W[3]\n",
    "    if root==1:\n",
    "        return (-b+np.sqrt(b*b-4*a*c))/(2*a)\n",
    "    if root==2:\n",
    "        return (-b-np.sqrt(b*b-4*a*c))/(2*a)\n",
    "    \n",
    "\n",
    "xdata = np.linspace(-1,2)\n",
    "\n",
    "plt.figure()\n",
    "\n",
    "plt.plot(xdata,calculate(xdata,1),'r')\n",
    "plt.plot(xdata,calculate(xdata,2),'r')\n",
    "\n",
    "plt.plot(x1,y1,'bo')\n",
    "plt.plot(x2,y2,'yo')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-1.  1.  1. -1.]\n"
     ]
    }
   ],
   "source": [
    "O = np.dot(X,W.T)\n",
    "print(O)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
